package cn.bigfire.wedesk.gui;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

public class ShowFrame {

    public static JFrame frame;
    public static ScreenCanvas canvas = new ScreenCanvas();
    public static ShowFrame showFrame;

    static {
        showFrame = new ShowFrame();
    }

    public ShowFrame() {
        frame = new JFrame();
        frame.setTitle("Capture");

        JPanel panel = new JPanel();
        frame.getContentPane().add(panel);

        frame.getContentPane().add(canvas);
        frame.setSize(800, 600);
        frame.setLocation(1920 - 800, 1080 - 700);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setAlwaysOnTop(true);
        frame.setVisible(true);

        //鼠标监听
        frame.addMouseListener(new MouseAdapter() {
//            @Override
//            public void mouseClicked(MouseEvent e) {
//                // 鼠标点击事件的处理逻辑
//                System.out.println("mouseClicked:" + e.getX() + "," + e.getY());
//            }

            @Override
            public void mousePressed(MouseEvent e) {
                System.out.println("mousePressed:" + e.getX() + "," + e.getY());
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                System.out.println("mouseReleased:" + e.getX() + "," + e.getY());
            }

            @Override
            public void mouseMoved(MouseEvent e) {
                System.out.println("mouseMoved:" + e.getX() + "," + e.getY());
            }
        });

        //键盘监听
        frame.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                // 当按下并释放键时调用
                System.out.println("Key typed: " + KeyEvent.getKeyText(e.getKeyCode()));
            }

            @Override
            public void keyPressed(KeyEvent e) {
                // 当按下键时调用
                System.out.println("Key pressed: " + KeyEvent.getKeyText(e.getKeyCode()));
            }

            @Override
            public void keyReleased(KeyEvent e) {
                // 当释放键时调用
                System.out.println("Key released: " + KeyEvent.getKeyText(e.getKeyCode()));
            }
        });

    }

}
